using System;
using System.Collections.Generic;
using System.Text;

using Liberty.Application.ServiceMemberManagement;
using Liberty.Domain.ServiceMemberManagement;
using Liberty.Persistence.Kernel;

using Peradigm.Framework.Domain.Security;

using Microsoft.VisualStudio.TestTools.UnitTesting;
//using NUnit.Framework.SyntaxHelpers;

using Rhino.Mocks;

namespace Tests.ApplicationTests.ServiceMemberManagement
{

#if DEBUG
    [TestClass()]
    public class ServiceMemberControllerTests : Object
    {
        #region Constants
        private const string 
            LASTNAME    = "TestLastName",
            DOBMONTH    = "1",
            DOBDAY      = "1",
            DOBYEAR     = "1999",
            CASENUMBER  = "23";
        #endregion

        #region SetUp and TearDown ServiceMemberControllerTests
        [TestInitialize()]
        public void SetUpServiceMemberControllerTests()
        {
        }

        [TestCleanup()]
        public void TearDownServiceMemberControllerTests()
        {
        }
        #endregion

        #region Test Methods
        [TestMethod()]
        public void TestNewServiceMember()
        {
            ServiceMemberController serviceMemberController = new ServiceMemberController();
            Assert.IsInstanceOfType( (object)serviceMemberController.NewServiceMemberFor( new User() ), typeof(ServiceMember) );
        }

        [TestMethod()]  
        public void TestServiceMembersMatchingCriteria()
        {
            ServiceMemberSearchCriteria serviceMemberSearchCriteria = 
                new ServiceMemberSearchCriteria( LASTNAME );

            // Create a "mock repository."  This will keep track of all of the mocking to be recorded and verified.
            MockRepository mocks = new MockRepository();

            // Create a list of fake service members that we want to have our mock broker return, so that we can test our controller
            // in isolation.  Testing of the actuall broker will of course be done in its own test fixture.
            List<ServiceMember> serviceMembers = new List<ServiceMember>();
            serviceMembers.Add( new ServiceMember() );

            // Create a mock service member broker.  This object will mock the real service member broker and return what we tell it to
            // return, namely a list of service members when sent the message service membersFor( criteria ).
            PersonBroker mockedBroker = mocks.DynamicMock<PersonBroker>( String.Empty );

            // Give our service memberController, the unit we are actually testing here, the mocking service member broker.
            ServiceMemberController serviceMemberController = new ServiceMemberController();
            serviceMemberController.PersonBroker = mockedBroker;

            // Tell the mock repository to expect that the message service membersFor(..) will be sent to the mocked service member broker,
            // to ignore the arguments sent to the mocked broker, and to always return our fake service members list when
            // this message is sent.
            
            Expect.On( mockedBroker ).Call( mockedBroker.ServiceMembersMatching( serviceMemberSearchCriteria ) ).IgnoreArguments().Return( serviceMembers );

            // Tell the mock repository to get ready to replay what was "recorded" above when the mocks are accessed.
            // Initializes mocked object.
            mocks.ReplayAll();
            
            Assert.AreEqual( serviceMembers,
                serviceMemberController.ServiceMembersMatchingCriteria( serviceMemberSearchCriteria ) );

            // Tell the mock repository to verify that all object interactions
            // happened as recorded/expected.  If they do not, the unit test will fail.
            mocks.VerifyAll();
        }
        #endregion

        #region Support Methods
        #endregion

        #region Data Elements
        #endregion

    }
#endif
	
}
